package com.tang.portal.controller.admin.sys;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tang.framework.core.controller.BaseController;
import com.tang.framework.core.domain.HttpResult;

import com.tang.framework.core.model.LoginUser;
import com.tang.common.model.req.ReqId;
import com.tang.portal.facade.admin.sys.SysUserFacade;
import com.tang.service.admin.model.req.ReqSysUser;
import com.tang.service.admin.model.req.ReqSysUserAdd;
import com.tang.service.admin.model.res.ResSysUserTableItem;
import com.tang.service.admin.model.res.ResSysUserDetail;
import com.tang.common.model.req.ReqIds;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import lombok.SneakyThrows;
import jakarta.annotation.Resource;

/**
 * @author tang jun liang
 * @Date ${gen.dateTime}
 */
@RestController
@RequestMapping("/sys/user")
public class SysUserController extends BaseController {

    @Resource
    private SysUserFacade sysUserFacade;


    @Operation(summary = "删除后台用户表")
    @PostMapping("/remove")
    public HttpResult<String> remove(@RequestBody ReqIds ids) {
        return sysUserFacade.remove(ids, getCurrLoginUser());
    }

    @Operation(summary = "后台用户表详情")
    @PostMapping("/detail")
    public HttpResult<ResSysUserDetail> detail(@RequestBody ReqId id) {
        return sysUserFacade.detail(id, getCurrLoginUser());
    }

    @Operation(summary = "后台用户表详分页")
    @PostMapping("/list")
    public HttpResult<IPage<ResSysUserTableItem>> list(@RequestBody ReqSysUser reqSysUser) {
        return sysUserFacade.list(reqSysUser, getCurrLoginUser());
    }


    @Operation(summary = "新增后台用户表")
    @PostMapping("/add")
    public HttpResult<String> add(@RequestBody ReqSysUserAdd sysUserAdd){
        return sysUserFacade.add(sysUserAdd);
    }

    @Operation(summary = "编辑后台用户表")
    @PostMapping("/update")
    public HttpResult<String> update(@RequestBody ReqSysUserAdd sysUserAdd){
        return sysUserFacade.update(sysUserAdd);
    }


    @Operation(summary = "导出excel-后台用户表")
    @PostMapping("/export")
    public void export(@RequestBody ReqIds ids){
        sysUserFacade.export(ids, httpServletResponse);
    }

    @Operation(summary = "导出excel-模版")
    @PostMapping("/export/template")
    public void exportTemplate(){
        sysUserFacade.exportTemplate(httpServletResponse);
    }

    @SneakyThrows
    @Operation(summary = "导入excel-后台用户表")
    @PostMapping("/import")
    public HttpResult<String> importExcel(MultipartFile file){
        return sysUserFacade.importExcel(file);
    }


    @Operation(summary = "用户详情")
    @PostMapping("/info")
    public HttpResult<LoginUser> info(){
        return HttpResult.ok(getCurrLoginUser());
    }



}
